from django.db import models
import datetime
# 用户表
class User(models.Model):
    username = models.CharField(max_length=20,verbose_name="用户名")
    phone = models.CharField(max_length=11,verbose_name="手机号")
    min_weight = models.IntegerField(verbose_name="体重范围最小值")
    max_weight = models.IntegerField(verbose_name="体重范围最大值")
# 体重明细表
class Weight(models.Model):
    user = models.ForeignKey(to=User, on_delete=models.CASCADE)
    create_time = models.DateField(auto_now_add=datetime.datetime.now(), verbose_name="时间")
    weight = models.DecimalField(max_digits=5,decimal_places=2,verbose_name="体重单位斤")
    img = models.ImageField(upload_to="static/img/",blank=True,verbose_name="照片")
    img_name = models.CharField(max_length=100,verbose_name="图片名",blank=True)


# 资产表
class Zichan(models.Model):
    user = models.ForeignKey(to=User,on_delete=models.CASCADE)
    create_time = models.DateField(auto_now_add = datetime.datetime.now(),verbose_name="创建时间")
    weixin = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="微信余额")
    zhifubao = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="支付宝余额")
    yinhangka = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="银行卡余额")
    touzi = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="投资金额")
    huabei = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="花呗借用")
    money = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="总金额")

# 投资表
class Touzi(models.Model):
    user = models.ForeignKey(to=User, on_delete=models.CASCADE)
    start_time = models.DateField(auto_now_add=datetime.datetime.now(), verbose_name="买入时间")
    start_money = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="买入金额")
    type = models.CharField(max_length=20,verbose_name="类型(基金、股票、期货等)")
    postscript = models.CharField(max_length=200,verbose_name="详情备注")
    end_time = models.DateField( verbose_name="卖出时间",blank=True,null=True)
    end_money = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="卖出金额",blank=True,null=True)
    sum_time = models.IntegerField(verbose_name="花费时间，单位为天",blank=True,null=True)
    shouyi = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="收益，回报金额 - 投资金额计算得来，可为负",blank=True,null=True)
    shouyilv = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="收益率",blank=True,null=True)
    statue = models.CharField(max_length=20,verbose_name="状态(0,已买入),(1,已卖出)",default=0)

# 花销流水表
class Liushui(models.Model):
    user = models.ForeignKey(to=User, on_delete=models.CASCADE)
    weixin = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="微信花销金额",blank=True,null=True)
    zhifubao = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="支付宝花销金额",blank=True,null=True)
    money = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="花销金额",blank=True,null=True)
    month = models.CharField(max_length=30,verbose_name="月份")
    statue = models.CharField(max_length=20,verbose_name="状态(0,未完),(1,已卖出)",default=0)
